using System;
using Gtk;
using System.Text;
using GLib;

namespace DaphneTranslator
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			Application.Init ();
			ExceptionManager.UnhandledException += HandleUnhandledException;					
			MainWindow win = new MainWindow ();		
			win.Show ();
			Application.Run ();
		}

		static void HandleUnhandledException (UnhandledExceptionArgs args)
		{
			args.ExitApplication = true;
			
			if (!(args.ExceptionObject is Exception))
				return;
			Exception ex = args.ExceptionObject as Exception;
			if (ex.InnerException != null)
				ex = ex.InnerException;
				
			StringBuilder sb = new StringBuilder ();
			sb.Append ("Exception: ");
			sb.Append (ex.Message);
			sb.AppendLine ();
			sb.Append ("Stack:");
			sb.AppendLine ();
			sb.Append (ex.StackTrace);
				
			MessageDialog msg = new MessageDialog (null, DialogFlags.Modal, MessageType.Error,
				                                      ButtonsType.Ok, false, sb.ToString ());
			msg.Title = "Fatal application error";
			msg.Run ();		
			msg.Destroy ();																		
		}
	}
}
